package com.example.spring.code.a06;

import jakarta.annotation.PostConstruct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class MyBean implements BeanNameAware, ApplicationContextAware, InitializingBean {

    private static final Logger log = LoggerFactory.getLogger(MyBean.class);

    @Override
    public void setBeanName(String name) {
        log.info("1. 当前 Bean 的名字：{}", name);
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        log.info("2. 当前容器对象是：{}", applicationContext);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        log.info("3. 当前 Bean：{} 执行初始化操作", this);
    }

    @Autowired
    public void aaa(ApplicationContext applicationContext) {
        log.info("使用 @Autowired 注入当前容器：{}", applicationContext);
    }

    @PostConstruct
    public void init() {
        log.info("当前 Bean：{} 使用 @PostConstruct 执行初始化操作", this);
    }

}
